mui.init({});


mui.plusReady(function(){
	loadDatas();
	
});

function loadDatas(){
	var self = plus.webview.currentWebview();
	var formId = self.formId;
	var sessionId =	plus.storage.getItem(KeyCfg.JSESSIONID);
	var url = UrlConfig.return_money;
	//var formData = $("#myform").serialize();
	var formData = {sessionId:sessionId};
	MuiEventMgr.ajax(url,{pars:formData,
	  	sfn : function(data){
	  		callback(data);
	  	},ffn : function(err){
	  		mui.alert("获取数据失败：["+err+"]");
	  	}
	 });
}

function callback(data){	
	var loanRecords = data.loanRecords;

	if(typeof(loanRecords) == 'undefined'){
		$(".returnMoney-header").css("display","none");
		$(".returnMoney-info").css("display","none");
		$(".returnMoney-table").css("display","none");
		$(".cmw_noinvest").css("display","");
		$(".mui-table-view").css("display","");
		//mui.alert("                         暂无记录!");
		return;
	}
	var htmlArr = [];
	for(var i=0,count=loanRecords.length; i<count; i++){
		var loanRecord = loanRecords[i];
		var html = getHtml(loanRecord);
		htmlArr[i] = html;
	}
	var htmlCodes = htmlArr.join("  ");
	$("#returnMoney-info").html(htmlCodes);

}

function getHtml(loanRecord){

	var tenderMoney = loanRecord.tenderMoney;
	var loanTitle = loanRecord.loanTitle;
	var loanTitle2 = loanTitle.replace('XR','XR<br/>');
	var receiveMoney = loanRecord.receiveMoney;
	var receiveRate = loanRecord.receiveRate;
	var loanRecordId = loanRecord.loanRecordId;

var htmls = [
		'<table class="returnMoney-table" border="0">',
				'<tbody>',
					'<tr>',
						'<td class="loanRecordId" ><a style="color: black;" id="'+loanRecordId+'" href="javascript:void(0)" onclick="openWindow('+loanRecordId+',\''+loanTitle+'\');" >'+'<u>'+loanTitle2+'</u>'+'</a></td>',
						'<td class="tenderMoney" >￥'+tenderMoney+'</td>',
						'<td class="receiveMoney" >￥'+receiveMoney+'</td>',
						'<td class="receiveRate">￥'+receiveRate+'</td>',
					'</tr>',
				'</tbody>',
			'</table>'
			];
	return htmls.join(" ");
}

function openWindow(id,loanTitle){
			var pars = {recordId:id,loanTitle:loanTitle};
			var cfg = {pars : pars};
			MuiEventMgr.open('returnMoneyList.html',cfg);	
}
